import React, {useState} from 'react';
import {View, Button, Text} from 'react-native';

import {ThemeContext} from './ThemeContext';
import Hoc1_useBtn from '../13_hoc高阶组件案例/13_1hoc高阶组件案例1__withFloatBtn';

import PageView from './PageView';

const RootView = ({text = ''} = {}) => {
  const [theme, setTheme] = useState('dark');
  return (
    <ThemeContext.Provider value={theme}>
      <View style={{position: 'relative'}}>
        <Text
          style={{textAlign: 'center', backgroundColor: '#ddd', color: 'red'}}>
          {text != '' ? text : ` 12-2Context实例演示应用主题配置`}
        </Text>
        <Button
          title="切换主题"
          onPress={() => {
            setTheme((state) => {
              if (state === 'dark') {
                return 'light';
              } else {
                return 'dark';
              }
            });
          }}
        />
        <View style={{width: '100%'}}>
          <PageView />
        </View>
      </View>
    </ThemeContext.Provider>
  );
};
// export default RootView;
export default Hoc1_useBtn(RootView);
